package com.jt.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;

public class SqlSessionUtil {
    private   static SqlSessionFactoryBuilder builder=null;
    private static SqlSessionFactory build = null;
    static {
        builder=  new SqlSessionFactoryBuilder();
        try {
            build=builder.build(Resources.getResourceAsReader("MyBatiss.xml"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static SqlSession getSqlSessionFactory(){
        SqlSession sqlSession = build.openSession();
        if(sqlSession == null){
            getSqlSessionFactory();
        }
        return sqlSession;
    }
}
